#ifndef BASEPORT_H
#define BASEPORT_H

#include <QObject>
#include <QDebug>
#include "DataType/PortStruct.h"
#include "System/DataTypeConver.h"
#include "Command/BaseCmd.h"

class BasePort : public QObject
{
    Q_OBJECT

public:
    Q_INVOKABLE BasePort(QObject *parent = 0):QObject(parent){}
    virtual ~BasePort(){}

    virtual void setPortParam(PortStruct portParam)
    {
        Q_UNUSED(portParam);
    }

    PortStruct portParam() const
    {
        return m_portParam;
    }

    virtual void open(){}
    virtual void close(){}
    virtual void write(PortStruct target,QByteArray data)
    {
        Q_UNUSED(target);
        Q_UNUSED(data);
    }

       virtual void get(PortStruct target,Package package)
           {
               Q_UNUSED(target);
               Q_UNUSED(package);
           }

    virtual void post(PortStruct target,Package package)
     {
         Q_UNUSED(target);
         Q_UNUSED(package);
     }



protected:
    PortStruct m_portParam;


signals:
    void receiveDataSignal(PortStruct source,QByteArray data);
    void isConnectedSignal(bool isConnect,PortStruct target);
    void clientDisconnectedSignal(PortStruct source);

public slots:

    void postDataSlot(PortStruct target,Package package)
    {
        qDebug()<<"*********BasePort postDataSlot";
        this->post(target,package);
    }
    void httpGetDataSlot(PortStruct target,Package package)
    {
         qDebug()<<"httpGetDataSlot slot";
        this->get(target,package);
    }
    void sendDataSlot(PortStruct target,QByteArray data)
    {
       // qDebug()<<"sendDataSlot slot";
        if(target.type() == m_portParam.type() && target.name() == m_portParam.name())
        {
            this->write(target,data);
        }
    }
    void openSlot(PortStruct port)
    {
        if(port.type() == m_portParam.type() && port.name() == m_portParam.name())
        {
            this->open();
        }
    }
    void closeSlot(PortStruct port)
    {
        if(port.type() == m_portParam.type() && port.name() == m_portParam.name())
        {
            this->close();
        }
    }

protected slots:
    virtual void readyReadSlot(){}
};

#endif // BASEPORT_H

